<template>
	<div class="sys-pos-container">
		<el-dialog v-model="state.isShowDialog" draggable :close-on-click-modal="false" width="700px">
			<template #header>
				<div style="color: #fff">
					<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit />
					</el-icon>
					<span> {{ props.title }} </span>
				</div>
			</template>
			<el-form :model="state.ruleForm" ref="ruleFormRef" label-width="auto" class="fl">
				<el-row :gutter="35">

					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-if="state.ruleForm.status">
						<el-form-item label="模板编号" prop="TemplateNo"
							:rules="[{ required: true, message: '模板编号不能为空', trigger: 'blur' }]">
							<el-input v-model="state.ruleForm.TemplateNo" placeholder="模板编号" clearable />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-if="!state.ruleForm.status">
						<el-form-item label="模板编号" prop="TemplateNo"
							:rules="[{ required: true, message: '模板编号不能为空', trigger: 'blur' }]">
							<el-input v-model="state.ruleForm.TemplateNo" placeholder="模板编号" clearable disabled />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="模板名称" prop="temlogicName"
							:rules="[{ required: true, message: '模板名称不能为空', trigger: 'blur' }]">
							<el-input v-model="state.ruleForm.temlogicName" placeholder="模板名称" clearable />
						</el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="是否请求第三方库位">
							<el-switch v-model="state.ruleForm.holdingPoint" inline-prompt active-text="是"
								inactive-text="否" :active-value="1" :inactive-value="0" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="点位数">
							<el-input v-model="state.ruleForm.pointNum" placeholder="请输入点位数" clearable />
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel">取 消</el-button>
					<el-button type="primary" @click="submit">确 定</el-button>
				</span>
			</template>
		</el-dialog>
	</div>
</template>

<script lang="ts" setup name="sysEditPos">
import { reactive, ref } from 'vue';

import { getAPI } from '/@/utils/axios-utils';
import { SysPosApi } from '/@/api-services/api';
import { UpdatePosInput } from '/@/api-services/models';
import { WmsApi } from '/@/api/wh';
import { ElMessage } from 'element-plus';

const props = defineProps({
	title: String,
});
const emits = defineEmits(['handleQuery']);
const ruleFormRef = ref();
const state = reactive({
	isShowDialog: false,
	ruleForm: {} as UpdatePosInput,
});

// 打开弹窗
const openDialog = (row: any) => {
	state.ruleForm = JSON.parse(JSON.stringify(row));
	console.log(state.ruleForm);

	state.isShowDialog = true;
	ruleFormRef.value?.resetFields();
};

// 关闭弹窗
const closeDialog = () => {
	emits('handleQuery');
	state.isShowDialog = false;
};

// 取消
const cancel = () => {
	state.isShowDialog = false;
};

// 提交
const submit = () => {
	ruleFormRef.value.validate(async (valid: boolean) => {
		if (!valid) return;
		if (state.ruleForm.status == undefined) {
			console.log(state.ruleForm);

			await WmsApi().modelPagePut(state.ruleForm)
				.then(function (res) {
					ElMessage.success('修改成功');

					closeDialog();
				})
				.catch(function (error) {
					console.log(error);

				});


		} else {

			await WmsApi().modelPageAdd(state.ruleForm)
				.then(function (res) {


					ElMessage.success('新增成功');
					closeDialog();
				})
				.catch(function (error) {
					console.log(error);

				});

		}
	});



}



// 导出对象
defineExpose({ openDialog });
</script>
<style lang="scss" scoped>
.fl {
	width: 70%;
	margin: 20px auto;
}
</style>